package com.woan.api.services;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.woan.api.idao.SysAdmininfoIDAO;
import com.woan.api.idao.SysAdmininfoMobileIDAO;
import com.woan.api.idao.SysRoleIDAO;
import com.woan.api.model.SysAdmininfo;
import com.woan.api.model.SysAdmininfoMobile;
import com.woan.api.model.SysRole;
import com.woan.api.vo.Json;
import com.woan.api.vo.VadmininfoSimpleList;
import com.woan.api.vo.VvideoList;

import net.sf.json.JSONObject;



public class UserServerServices {
	private SysAdmininfoIDAO sysadmininfoiDAO;
	private SysAdmininfoMobileIDAO sysadmininfomobileiDAO;
	private SysRoleIDAO sysroleiDAO;
	public SysAdmininfoIDAO getSysadmininfoiDAO() {
		return sysadmininfoiDAO;
	}



	public void setSysadmininfoiDAO(SysAdmininfoIDAO sysadmininfoiDAO) {
		this.sysadmininfoiDAO = sysadmininfoiDAO;
	}



	public SysAdmininfoMobileIDAO getSysadmininfomobileiDAO() {
		return sysadmininfomobileiDAO;
	}



	public void setSysadmininfomobileiDAO(
			SysAdmininfoMobileIDAO sysadmininfomobileiDAO) {
		this.sysadmininfomobileiDAO = sysadmininfomobileiDAO;
	}



	public SysRoleIDAO getSysroleiDAO() {
		return sysroleiDAO;
	}



	public void setSysroleiDAO(SysRoleIDAO sysroleiDAO) {
		this.sysroleiDAO = sysroleiDAO;
	}



	/*
	 * 
	 * 用户登录密码错误和账号过期判断
	 * 返回Json对象
	 */
	

	public Json loginInfo(String groupname,String username,String pwd,String devicenum){
		Json json = new Json();
		SysAdmininfo user = null;
		user = sysadmininfoiDAO.FindUserByGroupNameAndUsername(groupname,username,pwd);	
		SysAdmininfoMobile mobile = null;
		if(user != null)
		{	
			mobile = sysadmininfomobileiDAO.FindAdminMobileByUseridAndDeviceNum(user.getUid(), devicenum);
			//判断账号是否存在
			if(user.getType()!=2)
			{
				json.setResults("2");
				json.setErrMsg("该账号不允许在PAD上面登陆！");
			}
			else
			{
				json.setResults("0");
				json.setErrMsg("登陆成功");
				json.setItems("");
				json.setMobile(mobile);
				json.setAdmin(user);	
			}
		}
		else
		{
			json.setResults("1");
			json.setErrMsg("用户名或密码错误");
		}
		return json;
	}
	//登陆成功后保存设备信息
	public void saveMobileInfo(String uid,String devicenum,String devicetoken,String devicesys,String devicetype,String pushtype)
	{
		boolean flag = false;
		SysAdmininfoMobile mobile = new SysAdmininfoMobile();
		mobile.setUid(uid);
		mobile.setUserType("0");
		mobile.setDeviceNum(devicenum);
		mobile.setDeviceSys(devicesys);
		mobile.setDeviceToken(devicetoken);
		mobile.setDeviceType(devicetype);
		mobile.setIsauth("0");
		mobile.setPushType(pushtype);
		mobile.setPushornot("1");
		mobile.setServicecode("");
		SysAdmininfoMobile mobile_temp = sysadmininfomobileiDAO.FindAdminPadByObject(mobile);
		System.out.println("mobile_temp="+mobile_temp);
		if(mobile_temp == null)
		{
			flag=sysadmininfomobileiDAO.save(mobile);
		}
		else
		{
			mobile.setSeqid(mobile_temp.getSeqid());
			flag=sysadmininfomobileiDAO.save(mobile);
		}
				
	}
	
	
	public List<VadmininfoSimpleList> listGroupUser(String rid){
		List<VadmininfoSimpleList> admin = null;
		admin = sysadmininfoiDAO.FindVGroupUser(rid);
		return admin;
	}
	
}
